package com.example.mapexport.utils;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;

import androidx.appcompat.app.AlertDialog;

import com.example.mapexport.R;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;

public class Utils {
    public static boolean loadingShow = false;
    public static AlertDialog dialog;
    public static void showLoading(Context context) {
        if(null == dialog) {
            loadingShow = true;
            AlertDialog.Builder builder = new AlertDialog.Builder(context,R.style.Translucent_NoTitle);
            View customLayout = LayoutInflater.from(context).inflate(R.layout.loading_dialog, null);
            builder.setView(customLayout); // 设置自定义视图
            builder.setCancelable(false);
            dialog = builder.create();
            dialog.show();
        } else if(!loadingShow) {
            loadingShow = true;
            dialog.show();
        }
    }

    public static void hideLoading() {
        if(null != dialog && loadingShow) {
            loadingShow = false;
            dialog.dismiss();
        }
    }

    public static void copyTextToClipboard(Context context, String text) {
        ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("联系方式", text);
        clipboard.setPrimaryClip(clip);
    }
}
